<template>
    <div v-show="form.current">
        <FormItem>
            <Tooltip content="向上" style="float: left;cursor: pointer;"><span v-on:click="upIndex"><Icon type="md-arrow-up" size="22"></Icon></span></Tooltip>

            <Tooltip content="向下"  style="float: left;margin-left: 20px;cursor: pointer;"><span v-on:click="downIndex"><Icon type="md-arrow-down" size="22" ></Icon></span></Tooltip>
            <a v-if="$store.getters.per.wechat_function_menu_delete" href="javascript:void(0)" style="float: right;" v-on:click="delItem(form.id)">删除</a>
        </FormItem>
        <FormItem label="菜单名称">
            <IInput v-model="form.name" size="large" placeholder="菜单名称" />
            <Alert v-if="form.sub_button && form.sub_button.length>0" style="margin-top:15px;">已添加子菜单，仅可设置菜单名称。</Alert>
        </FormItem>
        <div v-show="form.sub_button && form.sub_button.length==0">
            <FormItem label="菜单内容">
                <RadioGroup v-model="form.menuType">
                    <Radio label="message">发送消息</Radio>
                    <Radio label="link">跳转网页</Radio>
                </RadioGroup>
            </FormItem>
            <FormItem v-show="form.menuType=='message'">
                <Keyword ref="keyword"  :callback="setKeyword"></Keyword>
            </FormItem>
            <FormItem v-show="form.menuType=='link'" label="页面地址">
                <IInput v-model="form.link" size="large" placeholder="页面地址" />
            </FormItem>
        </div>
    </div>

</template>
<script>
	import {Form,Input,Radio,Alert,Icon,Tooltip} from 'iview';

    import Keyword from 'admin/components/wechat/function/reply/reply-item/keyword';

    export default{
        props:{
            form :{
                type:Object
            },
            del :{
                type:Function
            },
            up :{
                type:Function
            },
            down :{
                type:Function
            },
            index:{
                type :Number
            },
            childindex:{
                type :Number
            },
        },
    	components:{
            'IInput' : Input,
            'IForm' : Form,
            'FormItem' : Form.Item,
            Radio,
            'RadioGroup' : Radio.Group,
            Keyword,
            Alert,
            Icon,
            Tooltip,
        },
        data(){
        	return {

        	}
        },
        methods:{
            //设置关键词
            setKeyword(keyword_id){
                this.form.keyword_id = keyword_id;
            },
            //删除菜单
            delItem(menu_id){
                this.del(this.index,this.childindex,menu_id);
            },
            //位置调整
            upIndex(){
                this.up(this.index,this.childindex);
            },
            downIndex(){
                this.down(this.index,this.childindex);
            }
        },
        mounted:function(){
            if(this.form.keyword_id!=0){
                this.$refs.keyword.setKeyword(this.form.keyword_id);    
            }
        }
    }
</script>